package SolodkovDA.applogic2;

import java.util.List;

import org.openqa.selenium.By;

import  SolodkovDA.applogic.FilmHelper;
import  SolodkovDA.model.Film;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

  public FilmHelper2(ApplicationManager2 manager) {
    super(manager.getWebDriver());
  }

  @Override
  public void createFilm(Film film) {
    pages.filmAddPage.ensurePageLoaded()
    	 .setTitleField(film.getTitle())
    	 .setYearField(film.getYear())
    	 .clickSubmitButton();
  }

  @Override
  public boolean deleteFilm(Film film) {
	  pages.filmListPage.ensurePageLoaded()
	  	   .startSearch(film.getTitle())
	  	   .checkPositiveSearchResults(film.getTitle());
	  pages.filmListPage.openFilmEditPage(film.getTitle());
	  return pages.filmViewPage.ensurePageLoaded().clickRemoveButton();
  }

  @Override
  public void searchFilm(String title) {
	  pages.filmListPage.ensurePageLoaded()
	  	   .startSearch(title);
  }

  @Override
  public boolean isSuccessCreatedFilm() {
	  return  pages.filmViewPage.waitPageLoaded();
  }
  
  @Override
  public boolean isNotSuccessCreatedFilm() {
	  pages.filmAddPage.checkRequiredLabel();
	  return  pages.filmAddPage.waitPageLoaded();
  }
  
  @Override
  public boolean isSuccessSearchFilm(String title) {
	  return  pages.filmListPage.checkPositiveSearchResults(title);
  }
  
  @Override
  public boolean isNotSuccessSearchFilm() {
	  return  pages.filmListPage.checkNegativeSearchResults();
  }
}
